package com.didi.gulimall.coupon.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.didi.gulimall.common.constant.CartConstant;
import com.didi.gulimall.common.constant.CouponConstant;
import com.didi.gulimall.common.utils.PageUtils;
import com.didi.gulimall.common.utils.Query;
import com.didi.gulimall.common.utils.R;
import com.didi.gulimall.common.vo.OrderItemVo;
import com.didi.gulimall.common.vo.OrderVo;
import com.didi.gulimall.coupon.dao.MemberPriceDao;
import com.didi.gulimall.coupon.entity.MemberPriceEntity;
import com.didi.gulimall.coupon.entity.SkuFullReductionEntity;
import com.didi.gulimall.coupon.entity.SkuLadderEntity;
import com.didi.gulimall.coupon.service.MemberPriceService;
import com.didi.gulimall.coupon.service.SkuFullReductionService;
import com.didi.gulimall.coupon.service.SkuLadderService;
import com.didi.gulimall.coupon.service.SpuBoundsService;
import com.didi.gulimall.coupon.vo.CalculateDiscountVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * @author 10626
 */
@Service("memberPriceService")
@Slf4j
public class MemberPriceServiceImpl extends ServiceImpl<MemberPriceDao, MemberPriceEntity> implements MemberPriceService {

    @Autowired
    private SkuFullReductionService skuFullReductionService;

    @Autowired
    private SpuBoundsService spuBoundsService;

    @Autowired
    private SkuLadderService skuLadderService;

    private ThreadLocal<CalculateDiscountVo> local = new ThreadLocal<>();

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MemberPriceEntity> page = this.page(
                new Query<MemberPriceEntity>().getPage(params),
                new QueryWrapper<MemberPriceEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public MemberPriceEntity getMemberTieredPrice(Long skuId, Long levelId) {
        return baseMapper.getMemberTieredPrice(skuId,levelId);
    }
}